$(function () {
    var strategyTimer = null;
    var strategyIdx = 0;
    var travelTimer = null;
    var travelIdx = 0;

    // 自动播放相关攻略图片
    function autoPlayStrategy() {
        strategyTimer = setInterval(function () {
            strategyIdx++;
            strategyIdx = strategyIdx > 2 ? 0 : strategyIdx;
            playSlide(strategyIdx, $('#_j_gl_slide_container'));
        }, 5000);
    }

    // 自动播放相关游记图片
    function autoPlayTravel() {
        travelTimer = setInterval(function () {
            travelIdx++;
            travelIdx = travelIdx > 2 ? 0 : travelIdx;
            playSlide(travelIdx, $('#_j_rec_slide_container'));
        }, 5000);
    }
    // 公用切换图片方法
    function playSlide(idx, $dom) {
        $dom.find('.gs_nav li').removeClass('on');
        $dom.find('.gs_nav li').eq(idx).addClass('on')
        $dom.find('.gs_content').animate({
            'left': -idx * 240 + 'px'
        });
    }
    // 点击切换图片
    $('#_j_rec_slide_container .gs_nav li').on('click', function (e) {
        // e.stopPropagation();
        clearInterval(travelTimer);
        travelIdx = $(this).attr('data-id');
        travelIdx = travelIdx > 2 ? 0 : travelIdx;
        playSlide(travelIdx, $('#_j_rec_slide_container'));
        autoPlayTravel();
    })
    // 点击切换图片
    $('#_j_gl_slide_container .gs_nav li').on('click', function (e) {
        // e.stopPropagation();
        clearInterval(strategyTimer);
        strategyIdx = $(this).attr('data-id');
        strategyIdx = strategyIdx > 2 ? 0 : strategyIdx;
        playSlide(strategyIdx, $('#_j_gl_slide_container'));
        autoPlayStrategy();
    })

    autoPlayTravel();
    autoPlayStrategy();


    $('body').on('click', function () {
        $('#_js_replyExpression').hide();
    });
    $('.newtab-prev').click(function (e) {
        e.stopPropagation();
        if (!$(this).hasClass('disabled')) {
            $(this).addClass('disabled')
            $('.newtab-next').removeClass('disabled')
            $('._j_switch_container').css('left', '0');

        }
    })

    $('.newtab-next').click(function (e) {
        e.stopPropagation();
        if (!$(this).hasClass('disabled')) {
            $(this).addClass('disabled')
            $('.newtab-prev').removeClass('disabled')
            $('._j_switch_container').css('left', '-324px');
        }
    })

    $('._j_face_tab').click(function (e) {
        e.stopPropagation();
        $('._j_face_tab').removeClass('cur');
        $(this).addClass('cur');
        $('.art_newface').addClass('hide');
        $('.art_newface').eq($(this).index()).removeClass('hide');
    });

    $('#_j_replyfacetrigger').click(function (e) {
        e.stopPropagation();
        $('#_js_replyExpression').show();
    });

    $('._j_emojiitem').click(function () {
        //$('._j_replyarea').append('(' + $(this).attr('title') + ')');
        $('._j_replyarea').val($('._j_replyarea').val() +  '(' + $(this).attr('title') + ')')
    })


    //分享
    $('.bs_share').on('mouseenter', function () {
        $(this).parents('.bar_share').next().show();
    }).on('mouseleave', function () {
        $(this).parents('.bar_share').next().hide();
    })

    $('.bs_pop').on('mouseenter', function () {
        $(this).show()
    }).on('mouseleave', function () {
        $(this).hide();
    });


    //分享
    function shareTo(stype) {
        var ftit = '';
        var flink = '';
        var lk = '';
        //获取文章标题
        ftit = document.title;
        //获取网页中内容的第一张图片地址作为分享图
        flink = document.images[0].src;
        if (typeof flink == 'undefined') {
            flink = '';
        }
        //当内容中没有图片时，设置分享图片为网站logo
        if (flink == '') {
            lk = 'http://' + window.location.host + '/static/images/logo.png';
        }
        //如果是上传的图片则进行绝对路径拼接
        if (flink.indexOf('/uploads/') != -1) {
            lk = 'http://' + window.location.host + flink;
        }
        //百度编辑器自带图片获取
        if (flink.indexOf('ueditor') != -1) {
            lk = flink;
        }
        //qq空间接口的传参
        if (stype == 'qzone') {
            window.open('https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + document.location.href + '?sharesource=qzone&title=' + ftit + '&pics=' + lk + '&summary=' + "fyukh;");
            //document.querySelector('meta[name="description"]').getAttribute('content')
        }
        //新浪微博接口的传参
        if (stype == 'sina') {
            window.open('http://service.weibo.com/share/share.php?url=' + document.location.href + '?sharesource=weibo&title=' + ftit + '&pic=' + lk + '&appkey=2706825840');
        }
        //生成二维码给微信扫描分享，php生成，也可以用jquery.qrcode.js插件实现二维码生成
        if (stype == 'wechat') {
            window.open('http://zixuephp.net/inc/qrcode_img.php?url=http://localhost:8888/destination/test');
        }
    }

    $('#aaaa').click(function () {
        console.log(1);
        shareTo(sina);
    })


});